/*
Copyright (C) 2022-2024 Inspur Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package controller

import (
	"did-service/auth"
	"did-service/bean/param"
	"did-service/common/http"

	"github.com/emicklei/go-restful"
)

// 授权给我的凭证列表
func (dc *DidController) ListCredentialToMePage(req *restful.Request, resp *restful.Response) {
	para := param.ListGrantCredentialParam{}
	para.PageNum = req.QueryParameter("pageNum")
	para.PageSize = req.QueryParameter("pageSize")
	para.IssuerName = req.QueryParameter("issuerName")
	para.CredentialName = req.QueryParameter("credentialName")

	walletId := auth.GetCurrentWalletId(req)
	para.WalletId = walletId

	credList, err := dc.srv.ListCredentialToMe(&para)
	if err != nil {
		log.Errorf("error: %v", err)
		http.Failed(resp, "获取授权给我的凭证列表失败!")
		return
	}
	http.OkWithData(resp, "成功", credList)
}

// 我授权的凭证列表
func (dc *DidController) ListCredentialToOtherPage(req *restful.Request, resp *restful.Response) {
	para := param.ListGrantCredentialParam{}
	para.PageNum = req.QueryParameter("pageNum")
	para.PageSize = req.QueryParameter("pageSize")
	para.IssuerName = req.QueryParameter("issuerName")
	para.CredentialName = req.QueryParameter("credentialName")

	walletId := auth.GetCurrentWalletId(req)
	para.WalletId = walletId

	credList, err := dc.srv.ListCredentialToOther(&para)
	if err != nil {
		log.Errorf("error: %v", err)
		http.Failed(resp, "获取授权给我的凭证列表失败!")
		return
	}
	http.OkWithData(resp, "成功", credList)
}
